package pers.fulsun.es.test._03_doc;

import java.io.IOException;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import pers.fulsun.es.test._01_ESClient;

public class _03_ESTest_Doc_Search {
  private static RestHighLevelClient client = _01_ESClient.getClient();

  public static void main(String[] args) throws IOException {
    //    // 1. 查询索引的所有数据
    //    SearchRequest request = new SearchRequest();
    //    request.indices("user");
    //
    //    // 构造查询条件
    //    SearchSourceBuilder builder = new SearchSourceBuilder();
    //    builder.query(QueryBuilders.matchAllQuery());

    GetRequest request = new GetRequest();
    request.index("user").id("1004");

    GetResponse response = client.get(request, RequestOptions.DEFAULT);
    System.out.println(response.isExists());
    System.out.println(response.getSourceAsString());

    // 关闭客户端连接
    client.close();
  }
}
